// miniprogram/pages/user/myBuildTeam/myAddTeam.js
// const db = cloud.database()
// const _ = db.command

import api from '../../../api/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusList: ['审核中', '组队中','已完成'],
    activeIndex: 0,
    bTeam:[],
    aTeam:[],
    status:['waitAndReject', 'need', 'full']
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.setData({
    //   aTeam:JSON.parse(options.aTeam)
    // })
   
  },
  onShow:function(){
    this.bTeam()
  },
  
  bTeam:function(){
    var index = this.data.activeIndex
    var status = this.data.status[index]
    
    var type = 'create'
    var params = {status,type}
    const that = this

    api.team.list(params).then(res=>{
      console.log(res.result)
      that.setData({
        aTeam:res.result.data.list
      })
    })
  },
  navbarChange: function(e) {
    this.setData({activeIndex: e.detail.index},()=>{
      this.bTeam()
    })
  },
  tapTeam: function(e) {
    console.log(e)
    var index = e.currentTarget.dataset.index
    var team = this.data.aTeam[index]
    var teamID = team._id
    console.log(team)
    wx.navigateTo({
      url: '../../team/detail/detail?team='+JSON.stringify(team)+'&teamID='+teamID,
    })
  },
})